package com.wc.blue_bridge_history.Java15B.C_分布式队列;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/13 12:10
 * @description
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010;
    // a代表每一个位置同步的出路，x代表当前同步到多少了
    static int[] a = new int[N];
    // 记录每一号码同步的多少次
    static int[] b = new int[N];
    static int n;
    static int x = 0;

    public static void main(String[] args) {
        n = sc.nextInt();
        while (sc.hasNext()) {
            String op = sc.next();
            if (op.equals("#")) break;
            if (op.equals("add")) {
                int element = sc.nextInt();
                a[0]++;
            } else if (op.equals("sync")) {
                int id = sc.nextInt();
                if (a[id] + 1 <= a[0]) {
                    a[id]++;
                    b[a[id]]++;
                    if (b[a[id]] == n - 1) x = a[id];
                }
            } else {
                out.println(x);
            }
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    boolean hasNext() {
        while (st == null || !st.hasMoreElements()) {
            String line = null;
            try {
                line = br.readLine();
                if (line == null) return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (line == null) {
                return false;
            }
        }
        return true;
    }
}